package com.qdu.servlet;

import com.qdu.dao.StudentDao;
import com.qdu.model.Student;
import com.sun.net.httpserver.HttpServer;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 这是处理根据班级名称查询学生列表的Servlet
 *
 * @author Anna
 */
@WebServlet(value = "/BLS")
public class BatchListServlet extends HttpServlet{

    StudentDao stuDao = new StudentDao();
    
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        
        String batchName = req.getParameter("batchName");
        List<Student> student =  stuDao.findAllByBatch(batchName);
        
        resp.setContentType("text/html;charset=UTF-8");
        PrintWriter out = resp.getWriter();
        
        out.println("<link rel=\"stylesheet\" href=\"css/bootstrap.min.css\"/>");
        out.println("<div class=\"container\">");
        out.println("<h1 class='text-center bg-success'>查询结果</h1>");
        out.println("<table class=\"table table-striped\">" +
"            <tr>" +
"                <th>学号</th>" +
"                <th>姓名</th>" +
"                <th>性别</th>" +
"                <th>班级</th>" +                   
"            </tr>");
        for(int i=0; i<student.size(); i++) {
            Student stu = student.get(i);
            out.println("<tr>");
            out.println("<th>" + stu.getSid() +"</th>");
            out.println("<th>" + stu.getSpassword()+"</th>");
            out.println("<th>" + stu.getSgender() +"</th>");
            out.println("<th>" + stu.getSbatch()+"</th>");
            out.println("</tr>");
        }
        out.println("</table>");
        out.println("</div>");
    }
    
}
